class Solution {
public:
    int brokenCalc(int startValue, int target) {
        int ret = 0;
        while (target > startValue)
        {
            if (target % 2 == 0)target /= 2;
            else target += 1;
            ret++;








        }
        return ret + startValue - target;

    }
};
class Solution {
public:
    string optimalDivision(vector<int>& nums) {
        string str;
        if (nums.size() == 1)
            return to_string(nums[0]);
        if (nums.size() == 2)
        {
            str += to_string(nums[0]);
            str += '/';
            str += to_string(nums[1]);
            return str;
        }
        str += to_string(nums[0]);
        str += '/';
        str += '(';
        for (int i = 1; i < nums.size(); i++)
        {
            str += to_string(nums[i]);
            if (i != nums.size() - 1)
                str += '/';
        }
        str += ')';
        return  str;





    }
}; class Solution {
public:
    vector<int> rearrangeBarcodes(vector<int>& b) {
        unordered_map<int, int>hash;
        int maxcount = 0;
        int maxval = 0;
        for (auto a : b)
        {
            if (maxcount < ++hash[a])
            {
                maxcount = hash[a];
                maxval = a;
            }

        }
        int m = b.size();
        vector<int>result(m);
        int index = 0;

        for (int i = 0; i < maxcount; i++)
        {
            result[index] = maxval;
            index += 2;


        }
        hash.erase(maxval);
        for (auto& [b, c] : hash)
        {
            for (int i = 0; i < c; i++)
            {
                if (index >= m)index = 1;
                result[index] = b;
                index += 2;



            }






        }
        return result;















    }
}; class Solution {
public:
    string reorganizeString(string s) {
        int m = s.size();
        int hash[26] = { 0 };
        int maxcount = 0;
        char maxval = ' ';
        for (auto ch : s)
        {
            if (maxcount < ++hash[ch - 'a'])
            {
                maxcount = hash[ch - 'a'];
                maxval = ch;

            }




        }
        if (maxcount > (m + 1) / 2)return "";



        string str(m, ' ');
        int index = 0;
        for (int i = 0; i < maxcount; i++)
        {
            str[index] = maxval;
            index += 2;
        }
        hash[maxval - 'a'] = 0;

        for (int i = 0; i < 26; i++)
        {
            for (int j = 0; j < hash[i]; j++)
            {
                if (index >= m)index = 1;
                str[index] = i + 'a';
                index += 2;



            }



        }





        return str;






    }
}; class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int prev = 0;
        int next = 0;
        int result = 1;
        if (nums.size() == 2 && nums[0] != nums[1])
            return 2;
        if (nums.size() == 2 && nums[0] == nums[1])
            return 1;

        for (int i = 0; i < nums.size() - 1; i++)
        {
            next = nums[i + 1] - nums[i];
            if (prev >= 0 && next < 0 || prev <= 0 && next>0)
            {
                result++;
                prev = next;
            }

        }
        return result;







    }
}; class Solution {
public:
    bool canJump(vector<int>& nums) {
        int cover = 0;
        for (int i = 0; i <= cover; i++)
        {
            cover = max(cover, i + nums[i]);
            if (cover >= nums.size() - 1)
                return true;





        }
        return false;



    }
}; class Solution {
public:
    int jump(vector<int>& nums) {
        int  end = 0;
        int maxpos = 0;
        int result = 0;
        for (int i = 0; i < nums.size() - 1; i++)
        {
            maxpos = max(maxpos, i + nums[i]);
            if (i == end)
            {
                end = maxpos;
                result++;
            }





        }
        return  result;







    }
}; class Solution {
public:
    bool canPlaceFlowers(vector<int>& flowerbed, int n) {
        int m = flowerbed.size();
        int count = 0;
        for (int i = 0; i < m; i++)
        {
            if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == m - 1 || flowerbed[i + 1] == 0))
            {
                count++;
                flowerbed[i] = 1;



            }
            if (count >= n)
                return true;




        }
        return false;
    }
}; class Solution {
public:
    int numWaterBottles(int numBottles, int numExchange) {
        int sum = numBottles;
        int emptybottles = numBottles;
        while (emptybottles >= numExchange)
        {
            int res = emptybottles / numExchange;
            emptybottles = res + emptybottles % numExchange;
            sum += res;
        }
        return sum;





    }
}; class Solution {
public:
    int twoCitySchedCost(vector<vector<int>>& costs) {
        sort(begin(costs), end(costs),
            [](const vector<int>& x1, const vector<int>& x2)
            {
                return (x1[0] - x1[1] < x2[0] - x2[1]);
            });
        int sum = 0;
        int n = costs.size() / 2;
        for (int i = 0; i < n; i++)
        {
            sum += costs[i][0] + costs[i + n][1];
        }
        return sum;









    }
}; class Solution {
public:
    bool isSubsequence(string s, string t) {
        if (s.size() != 0 && t.size() == 0)
            return false;
        int sptr = 0;
        int tptr = 0;
        while (sptr < s.size() && tptr < t.size())
        {
            if (s[sptr] == t[tptr])
            {
                sptr++;




            }
            tptr++;








        }
        return sptr == s.size();




    }
};